<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页 - 麻醉知识图谱</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
    <style>

        .button-container-right {
            display: flex;
            justify-content: flex-end;
        }
        .custom-wh {
            width: 80px; /* 设置特定宽度 */
/* height: 30px;*/
            /* 或者可以设置 padding，以适应需求 */
            padding: 15px;
            font-size: 15px;
        }

        /* 新增的内层容器样式，使其变小并居中 */
        .inner-container {
            max-width: 400px; /* 设置宽度，固定或百分比都可以 */
            margin: 0 auto; /* 自动左右居中 */
            padding: 10px; /* 可选：增加一些内边距 */
            width: 70%; /* 或者你可以设置一个固定宽度 */
        }

        /* 设置输入框的高亮效果 */
        .highlight-input {
            border: 1px solid #d6d8db; /* 浅蓝色边框 */
            border-radius: 5px; /* 圆角 */
            padding: 10px;
            height: 35px; /* 明确设置输入框的高度 */
/* width: 700px; /* 缩短输入框宽度 */
            font-size: 0.8rem; /* 更小的字体 */
            text-align: center;
            background-color: #f8f9fa; /* 背景颜色 */
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }
        .highlight-input::placeholder {
          font-size: 14px; /* 调整为更小的字体 */
          color: #6c757d; /* 可以更改颜色 */
        }
        /* 输入框获得焦点时的效果 */
        .highlight-input:focus {
            border-color: #9ecae1; /* 高亮紫色边框 */
            box-shadow: 0 0 10px rgba(171, 71, 188, 0.5); /* 紫色阴影 */
            outline: none;
        }

        /* 提示用户输入的占位符文本颜色 */
        .highlight-input::placeholder {
            color: #999;
            font-style: italic;
        }


        .button-container {
            display: flex;
            justify-content: center; /* 水平居中 */
/* width: 200px;*/
        }

        .glowing-button-register {
            background: linear-gradient(90deg, #6f42c1, #ab47bc, #6f42c1); /* 紫色渐变 */
            background-size: 200%;
            border: none;
            color: white;
            transition: 0.4s;
            box-shadow: 0 4px 15px rgba(111, 66, 193, 0.6); /* 紫色阴影 */
            animation: glowing 3s linear infinite;
        }

        .glowing-button-register:hover {
            background-position: 100%;
            transition: 0.4s;
            color: yellow;
        }
        .glowing-button-login {
            background: linear-gradient(90deg, #007bff, #00bfff, #007bff); /* 蓝色渐变 */
            background-size: 200%;
            border: none;
            color: white; /* 字体颜色调整为白色 */
            transition: 0.4s;
            box-shadow: 0 4px 15px rgba(0, 123, 255, 0.6); /* 蓝色阴影 */
            animation: glowing 3s linear infinite;
        }

        .glowing-button-login:hover {
            background-position: 100%;
            transition: 0.4s;
            color: yellow;
        }

        @keyframes glowing {
            0% {
                background-position: 0%;
            }
            50% {
                background-position: 100%;
            }
            100% {
                background-position: 0%;
            }
        }


        body {
            font-family: 'Noto Sans SC', Arial, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
            overflow-x: hidden;
        }

        .navbar-custom {
            background-color: #2E3B4E;
            padding: 1rem 2rem;
        }
        .nav-button {
            background-color: #2E3B4E;
            color: white;
            font-size: 1.1rem;
            margin-right: 1rem;
            border: none;
            padding: 8px;
        }

        .nav-button:hover {
            background-color: #1F2A3A;
            border-radius: 5px;
        }

        .navbar-custom .navbar-nav .nav-link {
            color: white;
            font-size: 1.1rem;
            margin-right: 1rem;
        }

        .navbar-custom .navbar-nav .nav-link:hover {
            background-color: #1F2A3A;
            border-radius: 5px;
        }

        .header-container {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            text-align: center;
            height: 100vh;
            background: linear-gradient(180deg, rgba(46, 59, 78, 1) 0%, rgba(31, 42, 58, 1) 100%);
            color: white;
            padding: 2rem;
        }

        .header-container h1 {
            font-size: 4rem;
            margin-bottom: 1rem;
            animation: fadeIn 2s;
        }

        .header-container p {
            font-size: 1.5rem;
            max-width: 600px;
            margin: 0 auto 2rem auto;
            animation: fadeIn 2s;
        }

        .btn-custom {
            background-color: #2E3B4E;
            color: white;
            padding: 0.5rem 1.5rem;
            font-size: 1.2rem;
            border-radius: 5px;
            transition: background-color 0.3s;
            animation: fadeIn 2s;
        }

        .btn-custom:hover {
            background-color: #1F2A3A;
            /* color: yellow;*/
        }

        .features {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 4rem 2rem;
            background-color: #ffffff;
        }

        .feature {
            flex: 1;
            margin: 1rem;
            text-align: center;
            padding: 2rem;
            background-color: #f0f0f0;
            border-radius: 10px;
            transition: transform 0.3s, box-shadow 0.3s;
            animation: fadeInUp 2s;
        }

        .feature:hover {
            transform: translateY(-10px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }

        .feature img {
            width: 80px;
            height: 80px;
            margin-bottom: 1rem;
        }

        .feature h3 {
            font-size: 1.8rem;
            margin-bottom: 1rem;
        }

        .feature p {
            font-size: 1rem;
            color: #666;
        }

        .section-container {
            padding: 4rem 2rem;
            text-align: center;
        }

        .section-container h2 {
            font-size: 2.5rem;
            margin-bottom: 1.5rem;
        }

        .section-container p {
            font-size: 1.2rem;
            max-width: 800px;
            margin: 0 auto;
            color: #666;
        }

        .footer {
            padding: 2rem;
            background-color: #2E3B4E;
            color: white;
            text-align: center;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @keyframes fadeInUp {
            from { transform: translateY(100%); }
            to { transform: translateY(0); }
        }

        .dl-container {
            margin-top: 150px;
            /*background-color: #0f6674;*/
            font-size: 16px;
        }

    </style>

</head>
<body>
<nav class="navbar navbar-expand-lg navbar-custom fixed-top">
    <div class="container-fluid">
        <a class="navbar-brand" href="/page">麻醉知识图谱</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="#">主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="checkLoginAndRedirect('/knowledge')">知识图谱</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="checkLoginAndRedirect('/profile')">个人中心</a>
                </li>
                <li class="nav-item">
                    <button id="logoutButton" class="nav-button"  onclick="logout()">注销</button>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="header-container">
    <h1 >欢迎来到麻醉知识图谱</h1>
    <p>一个专为医学专业人士设计的交互式学习和研究工具，旨在提供全面的、动态的麻醉学领域知识库。</p>
    <button id="loginButton" class="btn btn-custom glowing-button-login" data-bs-toggle="modal" data-bs-target="#loginModal">登录</button>
    &nbsp;&nbsp;
    <button id="registerButton" class="btn btn-custom glowing-button-register" data-bs-toggle="modal" data-bs-target="#registerModal">注册</button>
<!--    <button id="logoutButton" class="btn btn-custom" style="display: none;" onclick="logout()">注销</button>-->
</div>

<div class="features">
    <div class="feature">
        <img src="../img/feature1.png" alt="Feature 1">
        <h3>特性一</h3>
        <p>麻醉学知识节点快速定位</p>
    </div>
    <div class="feature">
        <img src="../img/feature2.png" alt="Feature 2">
        <h3>特性二</h3>
        <p>网状知识结构规划</p>
    </div>
    <div class="feature">
        <img src="../img/feature3.png" alt="Feature 3">
        <h3>特性三</h3>
        <p>扩展式知识理解优化</p>
    </div>
</div>

<div class="section-container about-container">
    <h2>关于我们</h2>
    <p>麻醉知识图谱是一个致力于提供全面麻醉学知识的互动平台，帮助医学专业人士更好地理解和应用麻醉知识。</p>
</div>

<div class="section-container contact-container">
    <h2>联系我们</h2>
    <p>如果您有任何问题或建议，请通过以下方式联系我们：</p>
    <p>邮箱: support@anesthesiaknowledge.com</p>
    <p>电话: +123 456 7890</p>
</div>

<div class="section-container latest-news-container">
    <h2>最新动态</h2>
    <p>敬请关注我们的最新动态和发布，了解麻醉学领域的最新进展和应用。</p>
</div>

<div class="modal fade dl-container" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
<!--            <div class="modal-header">-->
            <div class="button-container-right">
<!--                <h3 class="modal-title" id="loginModalLabel">登录</h3>-->
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="button-container">
            <h3 class="modal-title" id="loginModalLabel">登录</h3>
            </div>
            <div class="inner-container">
                <div class="modal-body">
                    <form id="login-form">
                        <div class="mb-3">
<!--                            <label for="login-username" class="form-label" >用户名</label>-->
<!--                            <input type="text" class="form-control highlight-input" id="login-username" placeholder="输入用户名" required>-->
                            <div class="input-group">
                                <span class="input-group-text" id="username-icon">
                                  <i class="fas fa-user"></i>
                                </span>
                                <input type="text" class="form-control highlight-input" id="login-username" placeholder="输入用户名" required>
                            </div>
                        </div>
                        <div class="mb-3">
<!--                            <label for="login-password" class="form-label">密码</label>-->
<!--                            <input type="password" class="form-control highlight-input" id="login-password" placeholder="输入密码" required>-->
                            <div class="input-group">
                                <span class="input-group-text" id="password-icon">
                                  <i class="fas fa-lock"></i>
                                </span>
                                <input type="password" class="form-control highlight-input" id="login-password" placeholder="输入密码" required>
                            </div>
                        </div>
                        <div class="button-container mb-3">
<!--                            <label class="form-label">用户类型</label><br>-->
                            <input type="radio" id="login-is-admin" name="login-user-type" value="admin">
                            <label for="login-is-admin">管理员</label>
<!--                            <label for="is-admin">管理员</label>-->
<!--                            <br>-->
                            &nbsp;&nbsp;
                            <input type="radio" id="login-is-user" name="login-user-type" value="user">
                            <label for="login-is-user">用户</label>
                            <!--                            <label for="is-user">用户</label>-->
                        </div>
                        <div class="button-container">
                            <button type="submit" class="btn glowing-button-login custom-wh" >登录</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="registerModal" tabindex="-1" aria-labelledby="registerModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content dl-container">
            <div class="button-container-right">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="button-container">
                <h3 class="modal-title" id="registerModalLabel">注册</h3>
            </div>
            <div class="inner-container">
                <div class="modal-body ">
                    <form id="register-form">
                        <div class="mb-3">
<!--                            <label for="register-username" class="form-label">用户名</label>-->
<!--                            <input type="text" class="form-control" id="register-username" required>-->
                            <div class="input-group">
                                <span class="input-group-text" id="username-icon-register">
                                  <i class="fas fa-user"></i>
                                </span>
                                <input type="text" class="form-control highlight-input" id="register-username" placeholder="输入用户名" required>
                            </div>
                        </div>
                        <div class="mb-3">
<!--                            <label for="register-password" class="form-label">密码</label>-->
<!--                            <input type="password" class="form-control" id="register-password" required>-->
                            <div class="input-group">
                                <span class="input-group-text" id="password-icon-register">
                                  <i class="fas fa-lock"></i>
                                </span>
                                <input type="password" class="form-control highlight-input" id="register-password" placeholder="输入密码" required>
                            </div>
                        </div>
<!--                        <div class="mb-3">-->
<!--                            <label class="form-label">用户类型</label><br>-->
<!--                            <input type="radio" id="register-is-admin" name="register-user-type" value="admin">-->
<!--                            <label for="is-admin">管理员</label><br>-->
<!--                            <input type="radio" id="register-is-user" name="register-user-type" value="user">-->
<!--                            <label for="is-user">用户</label>-->
<!--                        </div>-->
                        <div class="button-container mb-3">
<!--                            <label class="form-label">用户类型</label><br>-->
                            <input type="radio" id="register-is-admin" name="register-user-type" value="admin">
                            <label for="register-is-admin">管理员</label>
<!--                            <label for="is-admin">管理员</label>-->
<!--                            <br>-->
                            &nbsp;&nbsp;
                            <input type="radio" id="register-is-user" name="register-user-type" value="user">
                            <label for="register-is-user">用户</label>
                            <!--                            <label for="is-user">用户</label>-->
                        </div>

                        <div class="button-container">
                            <button type="submit" class="btn glowing-button-register custom-wh">注册</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="footer">
    <p>&copy; 2024 麻醉知识图谱. 保留所有权利.</p>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

<script>
    function checkLoginAndRedirect(destination) {
    fetch('/check_login_status')
        .then(response => response.json())
        .then(data => {
            if (!data.logged_in) {
                alert("请先登录！");
            } else {
                if (destination == '/knowledge'){
                    if (data.userRole == 'admin'){
                        window.location.href = '/knowledge_admin';
                    }else{
                        window.location.href = '/knowledge';
                    }
                }else{
                    window.location.href = destination;
                }

            }
        })
        .catch(error => {
            console.error('检查登录状态时发生错误:', error);
        });
    }
    document.addEventListener('DOMContentLoaded', function () {
        fetch('/check_login_status')
            .then(response => response.json())
            .then(data => {
                if (data.logged_in) {
                    document.getElementById('loginButton').style.display = 'none';
                    document.getElementById('registerButton').style.display = 'none';
                    document.getElementById('logoutButton').style.display = 'inline-block';
                } else {
                    document.getElementById('loginButton').style.display = 'inline-block';
                    document.getElementById('registerButton').style.display = 'inline-block';
                    document.getElementById('logoutButton').style.display = 'none';
                }
            });
    });

    document.getElementById('login-form').addEventListener('submit', function (event) {
        event.preventDefault();
        const username = document.getElementById('login-username').value;
        const password = document.getElementById('login-password').value;
        const userRole = document.querySelector('input[name="login-user-type"]:checked').value;
        
        if (!userRole) {
            alert('未选择用户类型!');
            return;
        }

        fetch('/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}&userRole=${encodeURIComponent(userRole)}`
        }).then(response => response.json())
            .then(data => {
                if (data.success) {
                    window.location.href = '/';
                } else {
                    alert(data.error);
                }
            });
    });

    document.getElementById('register-form').addEventListener('submit', function (event) {
        event.preventDefault();
        const username = document.getElementById('register-username').value;
        const password = document.getElementById('register-password').value;
        const userRole = document.querySelector('input[name="register-user-type"]:checked').value;
        
        if (!userRole) {
            alert('未选择用户类型!');
            return;
        }

        fetch('/register', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}&userRole=${encodeURIComponent(userRole)}`
        }).then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('注册成功，请登录！');
                    var registerModal = new bootstrap.Modal(document.getElementById('registerModal'));
                    registerModal.hide();
                } else {
                    alert(data.error);
                }
            });
    });

    function logout() {
        fetch('/logout')
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    window.location.href = '/';
                } else {
                    alert(data.error);
                }
            });
    }
</script>
</body>
</html>
